import React, { ReactElement, useState } from 'react';
import { Form, Button, Input, Modal } from 'antd';
import JobQuick from '@/pages/manufacture/jobQuick';

export interface SelectProps {
  width?: number;
  cRef?: any;
  name?: any;
  label?: string;
  placeholder?: string;
  noStyle?: boolean;
  disabled?: boolean;
  setCurrent: (item: any) => void;
  pType?: string;
  rules?: [{ required: boolean; message?: string | ReactElement }];
}
const JobSelect: React.FC<SelectProps> = (props: SelectProps) => {
  const [visible, setVisible] = useState<boolean>(false);
  const switchModal = () => {
    setVisible(!visible);
  };
  const setCurrent = (item: any) => {
    props.setCurrent(item);
    switchModal();
  };
  return (
    <>
      <Form.Item noStyle={props.noStyle} name={props.name} rules={props.rules}>
        <Input
          style={{ width: props.width }}
          placeholder={props.placeholder}
          disabled={props.disabled}
        />
      </Form.Item>
      <Form.Item noStyle={props.noStyle}>
        <Button type="primary" onClick={switchModal}>
          选择
        </Button>
      </Form.Item>
      <Modal
        title="工单选择"
        visible={visible}
        destroyOnClose={true}
        onCancel={switchModal}
        footer={false}
      >
        <JobQuick setCurrent={(item: any) => setCurrent(item)} />
      </Modal>
    </>
  );
};
export default JobSelect;
